package co.wizardattack.model;

import java.io.IOException;

import org.andengine.audio.music.Music;
import org.andengine.audio.music.MusicFactory;
import org.andengine.audio.music.MusicManager;
import org.andengine.audio.sound.Sound;
import org.andengine.audio.sound.SoundFactory;
import org.andengine.audio.sound.SoundManager;

import co.wizardattack.constants.ResourcesNames;

import android.content.Context;

public class Media {

	/**
	 * Constants
	 */
	private static final int NUMBER_OF_EFFECTS = 1;
	public static final int EFFECT_FIRE = 0;
	
	/**
	 * Managers
	 */
	private Context context;
	private SoundManager soundManager;
	private MusicManager musicManager;

	/**
	 * Sounds
	 */
	private Music miMusica;
	private Sound effects[];

	public Media(Context context, SoundManager soundManager, MusicManager musicManager) throws IOException {

		this.context = context;
		this.musicManager = musicManager;
		this.soundManager = soundManager;

		// Loading music
		miMusica = MusicFactory.createMusicFromAsset(musicManager, context, ResourcesNames.MUSIC_PATH);
		miMusica.setLooping(true);
		miMusica.setVolume(0.5f);

		// Loading effects
		effects = new Sound[NUMBER_OF_EFFECTS];
		effects[EFFECT_FIRE] = SoundFactory.createSoundFromAsset(soundManager, context, ResourcesNames.EFFECT_FIRE_PATH);
		effects[EFFECT_FIRE].setLooping(false);
	}
	
	public void playMusic() {
		this.miMusica.play();
	}
	
	public void playEffect(int effectId) {
		effects[effectId].play();
	}

}
